﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dapper.Logic.Service;
using Dapper.Modle;
using Dapper.Data.Service;
using Autofac;
using Dapper.Data.Implement;
using Dapper.Data;
using Dapper.Core;
using System.Web.Security;


namespace Dapper.Logic.Implement
{
    public class UserLogicImpl:ActionLogicImpl<User>, IUserLogicService
    {

        public User Login(string userName, string passWord)
        {
            User user;
            user=DateService.IUserDateService.GetUserByUserNameAndPassWord(userName,passWord);
            if (null == user)
            {
                return null;
            }
            else
            {
                
                //生成验证票据对象．
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(20), false, user.Group);
                //加密验证票
                string encrytedTicket = FormsAuthentication.Encrypt(authTicket);
                //配置节中Name的值作为Cookie的名字．
                Cookies.Add(FormsAuthentication.FormsCookieName, encrytedTicket);
                
                user.LoginTime = DateTime.Now;
                user.LastIp = Tools.GetRealIP();
                LogicService.IUserLogicService.Update(user);
                return user;
            }
        }
    }
}
